﻿Imports System.IO
Imports Microsoft.VisualBasic.FileIO
Public Class Form1

#Region "Global Variables"
    Private user_folder As String = Environment.GetEnvironmentVariable("UserProfile")
#End Region

#Region "Functions and Subs"
    Private Sub Empty_Stream()
        If Directory.Exists(user_folder + "/XslitXML/") = True Then
            Dim file As StreamWriter
            file = FileSystem.OpenTextFileWriter(user_folder + "/XslitXML/xtitle.xml", False)
            file.WriteLine("")
            file.Close()
        ElseIf Directory.Exists(user_folder + "/XslitXML/") = False Then
            Directory.CreateDirectory(user_folder + "/XslitXML/xtitle.xml")
            Dim file As StreamWriter
            file = FileSystem.OpenTextFileWriter(user_folder + "/XslitXML/xtitle.xml", False)
            file.WriteLine("")
            file.Close()
        End If
    End Sub

    Private Sub WriteFile()
        If Directory.Exists(user_folder + "/XslitXML/") = True Then
            Dim file As StreamWriter
            file = FileSystem.OpenTextFileWriter(user_folder + "/XslitXML/xtitle.xml", False)
            file.WriteLine("<" + Tagbox1.Text + ">" + Statusbox1.Text + "</" + Tagbox1.Text + ">")
            file.Close()
        ElseIf Directory.Exists(user_folder + "/XslitXML/") = False Then
            Directory.CreateDirectory(user_folder + "/XslitXML/xtitle.xml")
            Dim file As System.IO.StreamWriter
            file = FileSystem.OpenTextFileWriter(user_folder + "/XslitXML/xtitle.xml", False)
            file.WriteLine("<" + Tagbox1.Text + ">" + Statusbox1.Text + "</" + Tagbox1.Text + ">")
            file.Close()
        End If
    End Sub
#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Tagbox1.Text = "" Then
            MsgBox("ERROR! Tagbox is empty. Without the Tag in the tagbox this program cannot function any further. PLEASE put some text in the box" + _
                   MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "ERROR!")
        Else
            If Statusbox1.Text = "" Then
                Empty_Stream()
            Else
                WriteFile()
            End If
        End If
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        'If closebox1.Checked = True Then
        'Write_Empty_Stream()
        'End If
        If Exit_Clear.Checked = True Then
            Empty_Stream()
        End If

        'If Close_Minimize.Checked = True Then
        '    Me.Hide()
        '    Me.ShowInTaskbar = False
        'ElseIf Close_Minimize.Checked = False Then
        '    Me.Close()
        'End If

        'Me.Hide()
        'MsgBox("Program is closing do you want to clear the title file?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Clear Title File?")
        'If MsgBoxResult.Yes Then
        '     Empty_Stream()
        ' End If
    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Process.Start(LinkLabel1.Text)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        URLBox.Text = "file://" + user_folder + "/XslitXML/xtitle.xml"
    End Sub

    Private Sub Copy_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Copy_Button.Click
        AppIcon1.BalloonTipText = "Link Copied"
        AppIcon1.BalloonTipTitle = "Copied!"
        AppIcon1.ShowBalloonTip(2000)
        URLBox.Copy()
    End Sub

 
    Private Sub Exit_Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Exit_Clear.Click
        If Exit_Clear.Checked = True Then
            Exit_Clear.Checked = False
        ElseIf Exit_Clear.Checked = False Then
            Exit_Clear.Checked = True
        End If
    End Sub

    Private Sub Close_Minimize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Close_Minimize.Click
        If Close_Minimize.Checked = True Then
            Close_Minimize.Checked = False
        ElseIf Close_Minimize.Checked = False Then
            Close_Minimize.Checked = True
        End If
    End Sub

    Private Sub Force_Exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Force_Exit.Click
        Me.Close()
    End Sub
End Class
